import store from '@/store'

export const usersRolesPermissions = {
  // All
  admin: {
    root: ["*", "admin"]
  },
  // 首页
  home: {
    root: ["*", "admin", "main", "home"]
  },
  // 用户管理
  usersManagement: {
    root: ["*", "admin", "usersManagement"],
    // 账号
    account: {
      root: ["*", "admin", "usersManagement.account"],
      query: ["*", "admin", "usersManagement.account.query"],
      add: ["*", "admin", "usersManagement.account.add"],
      edit: ["*", "admin", "usersManagement.account.edit"],
      delete: ["*", "admin", "usersManagement.account.delete"],
      details: ["*", "admin", "usersManagement.account.details"]
    }
  }
}

export function hasUsersPermission(key) {
  var bIs = false
  if (key) {
    key.map(item => {
      if (store.getters.roles.some(role => role.indexOf(item) >= 0)) {
        bIs = true
      }
    })
  } else {
    bIs = false
  }
  return bIs
}
